# -*- coding:utf-8 -*- 
# Author: json_steve

from flask import Blueprint, current_app,make_response
from flask_wtf.csrf import generate_csrf

html = Blueprint("html", __name__)


# http://127.0.0.1:5000/index.html
# http://127.0.0.1:5000/favicon.ico
# @html.route('/<file_name>')
@html.route('/<re(".*"):file_name>')
def get_html_file(file_name):
    if not file_name:
        file_name = 'index.html'
    if file_name != 'favicon.ico':
        file_name = 'html/'+file_name
    # print(file_name)
    # 发送csrf_token在cookie 里
    response = make_response(current_app.send_static_file(file_name))
    # 生成csrf  保存在session中
    csrf_token = generate_csrf()
    # 放到cookie一份给浏览器获取 放到ajax 的 "X-CSRFToken": getCookie("csrf_token")
    response.set_cookie('csrf_token', csrf_token)

    return response
